home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / cli / Ver2Comm.lha / v2c_1.1.c < prev   
C/C++ Source or Header  |  1992-09-02  |  5KB  |  151 lines

  1. /* What is this?
  2.      Its a short utility that will comment a file with its own versionstring.
  3.  
  4.    Who needs this?
  5.      Someone who uses some kind of directory utility which displays file
  6.      comment but not version. You can select file, click v2c, rescan
  7.      the directory and just read the comment.
  8.  
  9.    Why is this useful?
  10.      Sometimes you get some kind of a short utility which you allready have
  11.      but filesizes don't match. It's a short way to find out which one is newer.
  12.  
  13.    How do I use it?
  14.      Usage: V1.0 "v2c <Filename>" (no wildcards)
  15.  
  16.             V1.1 "v2c <Filename> [DOT] [ERASE] [NONAME] [QUIET]" for V1.1
  17.     Desc. of parameters:
  18.          DOT: if no version string is found, a dot (.) will be put instead.
  19.        ERASE: This option will erase last comment if there was any before.
  20.               Otherwise the version will be inserted at the beginning. Try it
  21.       NONAME: This option will erase filename from version string.
  22.               example: file "v2c" Version: "$VER: v2c 1.0"  comment: "1.0"
  23.        QUIET: no text will be written to output()
  24.  
  25.    Bugs?
  26.      Sometimes when wildcards are used nothing happens and
  27.      ERROR_BUFFER_OVERFLOW (303) is written to output(). This happened a lot
  28.      when ap_Buf in AnchorPath structure was set to 233 bytes and most of
  29.      the times crashed Amiga when it was set to 1 byte. It is set to 488
  30.      bytes in this compiled version and the problem didn't occur yet. If it
  31.      does please do let me know and I will set it to a higher value.
  32.  
  33.    Legal stuff?
  34.      Cardware !!! It's the same as shareware but if you use this utility
  35.      regular you don't have to send me money but you should send me a
  36.      postcard to the address below. If you decide to do so (what you should)
  37.      please send me a postcard with a picture of the city you live in.
  38.  
  39.    This code is crap!
  40.      It is my gift to you.
  41.  
  42.    This is just what I have been waiting for and I want to contact the
  43.    author and congratulate him!
  44.      Great! Glad that at least someone is happy. If you like this, use it
  45.      or want a better version, write to me and I'll be happy to help you. 
  46.  
  47.      My address is:
  48.  
  49.      Drago Fiser
  50.      Plecnikova 5
  51.      62000 Maribor
  52.      Slovenia, Europe
  53.      Tel. +386 (0)62 31956
  54.  
  55.      E-mail: Drago.Fiser@uni-mb.si
  56.  
  57.  
  58. And remember to send me a postcard!
  59.  
  60. */
  61.  
  62. #include <proto/dos.h>
  63.  
  64. static struct RDArgs *rdargs;
  65. static LONG args[5];
  66.  
  67.  
  68. void StrCa(char *str1, char *str2, char *str3)
  69. { int i,j;
  70.  
  71.   for (i=0;(i<79) && (str1[i]!='\0');i++) str3[i]=str1[i];
  72.   for (j=0;(i<79) && (str2[j]!='\0');j++) str3[i++]=str2[j];
  73.   str3[i]='\0';
  74.   return;
  75. }
  76.  
  77. int GetVersion(BPTR fil,char *filcomm)
  78. { char d, *versionstring="$VER: v2c 1.1 (20.12.1994) by Drago Fiser";
  79.   int i=0;
  80.   ULONG filelength, st;
  81.  
  82.   Seek(fil,0,OFFSET_END);
  83.   filelength=Seek(fil,0,OFFSET_BEGINNING);
  84.   for (st=0; st<filelength; st++) {
  85.    if ((d= FGetC(fil)) ==versionstring[i]) {
  86.     if ((++i)==5) { FGets(fil,filcomm,80); return(1); }
  87.    } else i=0;
  88.   }
  89.   return(0);
  90. }
  91.  
  92. void Cis(struct FileInfoBlock *fibb)
  93. { BPTR Fil;
  94.   char filcomm[80],*verstr,*filename,*filecomment;
  95.  
  96.   filename= fibb->fib_FileName; filecomment= fibb->fib_Comment;
  97.   if (!args[4]) Printf("%s",filename);
  98.   if (Fil=Open(filename,MODE_OLDFILE))
  99.    { if (GetVersion(Fil,filcomm))
  100.      { for(verstr=filcomm;*verstr==' ';verstr++);
  101.        if (args[3]<0) 
  102.         { int i; for(i=0; (filename[i] & 223)==(*verstr & 223);i++) verstr++;
  103.           for(;*verstr==' ';verstr++);
  104.         }
  105.       if (!args[4]) Printf("\t\t%s\n",verstr);
  106.       if (args[2]<0) SetComment(filename,verstr);
  107.        else { char newcomm[80], newcom2[80];
  108.               StrCa(verstr,";",newcom2);
  109.               StrCa(newcom2,filecomment,newcomm);
  110.               SetComment(filename,newcomm);
  111.             }
  112.      }
  113.     else 
  114.      { if (!args[4]) PutStr("\t.\n");
  115.        if (args[1]<0) 
  116.        { if (args[2]<0) SetComment(filename,".");
  117.          else { char newcomm[80]; StrCa(".",filecomment,newcomm);
  118.                 SetComment(filename,newcomm);
  119.               }
  120.        }
  121.      }
  122.     Close(Fil);
  123.    } else if (!args[4]) Printf("Couldn't open file %s\n",filename);
  124. }
  125.  
  126.  
  127. main(void)
  128. {
  129.  LONG err;
  130.  BPTR olddir;
  131.  struct AnchorPath ap;
  132.  
  133.   if ((rdargs=ReadArgs("FILENAME/A,DOT/S,ERASE/S,NONAME/S,QUIET/S",args,NULL))==NULL)
  134.    { if (!args[4]) PutStr("Bad arguments.\n"); }
  135.   else 
  136.   { ap.ap_BreakBits=SIGBREAKF_CTRL_C;
  137.     for (err= MatchFirst((char *)args[0],&ap); err!= ERROR_NO_MORE_ENTRIES; err= MatchNext(&ap))
  138.     {
  139. if (err) if (!args[4]) Printf(" Error :%ld\tDirEntryType :%ld\ton file :%s\n",err,ap.ap_Info.fib_DirEntryType,ap.ap_Info.fib_FileName);
  140.       if ((ap.ap_Info.fib_DirEntryType < 0) && (err==0))
  141.       { olddir=CurrentDir(ap.ap_Current->an_Lock);
  142.         Cis(&ap.ap_Info);
  143.         CurrentDir(olddir);
  144.       }
  145.     }
  146.     MatchEnd(&ap);
  147.   }
  148.   FreeArgs(rdargs);
  149. if (!args[4]) Printf("All done!\n");
  150. }
  151.